import type { IStack } from "../types";

export default class StackArr<T> implements IStack<T> {
  private items: T[];
  constructor() {
    this.items = [];
  }
  push(item: T): void {
    this.items.push(item);
  }
  pop(): T | undefined {
    return this.items.pop();
  }
  peek(): T | undefined {
    return this.items[this.items.length - 1];
  }
  isEmpty(): boolean {
    return this.items.length === 0;
  }
  size(): number {
    return this.items.length;
  }
  clear(): void {
    this.items = [];
  }
  toString(): string {
    return this.items.toString();
  }
}
